package top.finen.miniweapp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import top.finen.miniweapp.service.impl.UrlRequestServiceImpl;

@RestController
@RequestMapping("/api_v1")
public class CommonController {
    private final static String AppID = "wxb27ac135346a05ef";
    private final static String secret = "28b70d35360b5bdacd2a5f9992b8f6fd";
    private final static String grantType = "authorization_code";

    @Autowired
    UrlRequestServiceImpl urlRequestService;

    @RequestMapping(value = "/get/params", method = RequestMethod.POST)
    public String getParams(String code){
        String url = "https://api.weixin.qq.com/sns/jscode2session?appid="+AppID+"&secret="+secret+"&js_code="+code
                +"&grant_type="+grantType;
        String response = urlRequestService.httpClient(url);

        return response;
    }
}
